<template>
  <!-- 搜索栏部分 -->
  <el-card class="search-card">
    <el-form :model="searchForm" label-width="80px" inline>
      <el-form-item label="客户编码">
        <el-input v-model="searchForm.code" placeholder="客户编码" clearable />
      </el-form-item>
      <el-form-item label="客户名">
        <el-input v-model="searchForm.name" placeholder="客户名" clearable />
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="searchForm.status" style="width:100px" placeholder="请选择状态" clearable>
          <el-option label="启用" value="1" />
          <el-option label="禁用" value="0" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleSearch">搜索</el-button>
        <el-button @click="resetSearch">重置</el-button>
      </el-form-item>
    </el-form>
  </el-card>
  <!-- 列表 -->
  <el-card class="table-card">
    <el-radio-group v-model="customerCode" style="width: 100%">
    <el-table
        :data="customerList"
        border
        stripe

    >
    <el-table-column>
      <template #default="scope">
        <el-radio :value="scope.row.code"/>
      </template>
    </el-table-column>

      <el-table-column prop="code" label="客户编号" />
      <el-table-column prop="name" label="客户名" />
      <el-table-column prop="address" label="客户地址" />
      <el-table-column prop="contactPerson" label="联系人" />
      <el-table-column prop="phone" label="联系电话" />
      <el-table-column prop="status" label="状态" width="80">
        <template #default="scope">
          <el-tag :type="scope.row.status == '1' ? 'success' : 'danger'">
            {{ scope.row.status == '1' ? '启用' : '禁用' }}
          </el-tag>
        </template>
      </el-table-column>
    </el-table>
    </el-radio-group>
  </el-card>
  <el-row style="margin: 40px">
    <el-button @click="doSelectCustomer">确定</el-button>
  </el-row>
</template>

<script setup>
//导入
import {ref,onMounted} from "vue";
import {getCustomerPage} from "@/api/customer.js";
//--------------属性申明  ⬇
const customerList = ref([])

const searchForm = ref({
  code:"",
  name:"",
  status:""
})
const customerCode = ref(null)
const emit = defineEmits(["selectCustomer"])
//--------------属性申明  ⬆
//--------------函数申明  ⬇
//查询
const handleSearch = ()=>{
  getCustomerPage(1,1000,searchForm.value).then(res=>{
    customerList.value = res.data.list
  })
}
const doSelectCustomer = ()=>{
  emit("selectCustomer",customerCode.value)
}
//重置查询列表
const resetSearch = ()=>{
  searchForm.value = {
    code:"",
    name:"",
    status:""
  }
}
onMounted( ()=>{
  handleSearch();
})
//--------------函数申明  ⬆

</script>

<style scoped>

</style>